<%
   'Programed By DarkFlash
%>
<%
	Option Explicit

	Response.Expires = -1
	Response.Buffer = true
	Response.Flush
%>
<!-- #include file="../include/dbFunc.asp" -->
<!-- #include file="../include/stringFunc.asp" -->
<%
	Dim db,sql,rs,i
	Dim idx
	Dim arrProduct(),regDate,bCode,orderName,orderTel,orderEmail
	Dim receiverName,receiverTel,receiverAddr,note,buyType,buyMoney,sendMoney,totalMoney,mileage,state
	
	idx = Request("idx")
	
	Set db = Server.CreateObject("ADODB.Connection")
	db.Open fnDbCs("127.0.0.1","5h5m")
	
	sql = "SELECT a.pName,b.sendMethod,a.pCount,a.pMoney,a.state FROM "
	sql = sql & "buyPTable a INNER JOIN "
	sql = sql & "pDB b ON a.pIdx = b.idx WHERE "
	sql = sql & "a.sIdx = " & idx & " ORDER BY "
	sql = sql & "a.pName"
	Set rs = db.Execute(sql)
	
	ReDim arrProduct(5,-1)
	Do Until rs.Eof
		ReDim Preserve arrProduct(5,UBound(arrProduct,2)+1)
		arrProduct(0,UBound(arrProduct,2)) = rs("pName")
		arrProduct(1,UBound(arrProduct,2)) = rs("sendMethod")
		arrProduct(2,UBound(arrProduct,2)) = rs("state")
		arrProduct(3,UBound(arrProduct,2)) = rs("pMoney")
		arrProduct(4,UBound(arrProduct,2)) = rs("pCount")
		arrProduct(5,UBound(arrProduct,2)) = CStr(int(rs("pCount")) * int(rs("pMoney")))
	
		rs.MoveNext
	Loop
	Set rs = nothing
	
	sql = "SELECT regDate,bCode,orderName,orderTel1,orderTel2,orderTel3,"
	sql = sql & "orderEmail1,orderEmail2,receiverName,receiverTel1,receiverTel2,receiverTel3,"
	sql = sql & "receiverZip1,receiverZip2,receiverAddr1,receiverAddr2,note,"
	sql = sql & "buyType,buyMoney,sendMoney,state FROM "
	sql = sql & "buyTable WHERE "
	sql = sql & "idx = " & idx
	Set rs = db.Execute(sql)
	
	regDate = rs("regDate")
	bCode = rs("bCode")
	orderName = rs("orderName")
	orderTel = rs("orderTel1") & "-" & rs("orderTel2") & "-" & rs("orderTel3")
	orderEmail = rs("orderEmail1") & "@" & rs("orderEmail2")
	receiverName = rs("receiverName")
	receiverTel = rs("receiverTel1") & "-" & rs("receiverTel2") & "-" & rs("receiverTel3")
	receiverAddr = rs("receiverZip1") & "-" & rs("receiverZip2") & " " & rs("receiverAddr1") & " " & rs("receiverAddr2")
	note = rs("note")
	buyType = rs("buyType")
	buyMoney = rs("buyMoney")
	sendMoney = rs("sendMoney")
	totalMoney = CStr(int(buyMoney) + int(sendMoney))
	state = rs("state")
	Set rs = nothing
	
	sql = "SELECT COUNT(mileage-0) FROM "
	sql = sql & "mileage WHERE "
	sql = sql & "sIdx = " & idx
	Set rs = db.Execute(sql)
	
	mileage = rs(0)
	Set rs = nothing
	
	db.Close
	Set db = nothing
%>
<script language="JavaScript">
<!--
var arrProduct = new Array();

<%	For i = 0 To UBound(arrProduct,2) %>
if(!arrProduct[<%=i%>]) arrProduct[<%=i%>] = new Array();
arrProduct[<%=i%>][0] = "<%=arrProduct(0,i)%>";
arrProduct[<%=i%>][1] = "<%=arrProduct(1,i)%>";
arrProduct[<%=i%>][2] = "<%=arrProduct(2,i)%>";
arrProduct[<%=i%>][3] = "<%=Mid(formatCurrency(arrProduct(3,i)),2)%>";
arrProduct[<%=i%>][4] = "<%=arrProduct(4,i)%>";
arrProduct[<%=i%>][5] = "<%=Mid(formatCurrency(arrProduct(5,i)),2)%>";
<%	Next %>

var regDate = "<%=formatDateTime(regDate,vbShortDate)%>";
var bCode = "<%=fnCheckTag(bCode,"J1")%>";
var orderName = "<%=fnCheckTag(orderName,"J1")%>";
var orderTel = "<%=fnCheckTag(orderTel,"J1")%>";
var orderEmail = "<%=fnCheckTag(orderEmail,"J1")%>";
var receiverName = "<%=fnCheckTag(receiverName,"J1")%>";
var receiverTel = "<%=fnCheckTag(receiverTel,"J1")%>";
var receiverAddr = "<%=fnCheckTag(receiverAddr,"J1")%>";
var note = "<%=fnCheckTag(note,"J1")%>";
var buyType = "<%=fnCheckTag(buyType,"J1")%>";
var buyMoney = "<%=Mid(formatCurrency(buyMoney),2)%>";
var sendMoney = "<%=Mid(formatCurrency(sendMoney),2)%>";
var totalMoney = "<%=Mid(formatCurrency(totalMoney),2)%>";
var state = "<%=fnCheckTag(state,"J1")%>";
var mileage = "<%=Mid(formatCurrency(mileage),2)%>";

parent.setBuy(arrProduct,regDate,bCode,orderName,orderTel,orderEmail,receiverName,receiverTel,receiverAddr,note,buyType,buyMoney,sendMoney,totalMoney,state,mileage);
document.location.href = "about:blank";
//-->
</script>